<template>
  <div class="box">
    <div class="items">
      <div class="item" @click="clickItem(item.id)" v-for="item in items" :key="item.id">
         <div class="item-info">
           <img v-lazy="item.pic" class="item-img" >
         </div>
           <div class="item-action">
              <h3>{{item.name}}</h3>
            <div class="price">
              ￥{{item.minPrice}}
            </div>
              <van-icon
              @click.stop="clickAddCart(item.id, item)"
              name="gouwuche" class-prefix="icon" size="24" color="#ff734c"></van-icon>
          </div>

      </div>
    </div>
  </div>
</template>

<script>
export default {
  /* 这是在home页面传的需要传到子组件 父传子 props
 */
  props: {
    items: {
      type: Array

    }
  },
  methods: {
    clickAddCart (id, item) {
      // 点击加入购物车图标
      this.$emit('clickAddIcon', { id, item })
    },
    clickItem (id) {
      // 点击商品
      this.$emit('clickItem', id)
    }
  }
}
</script>

<style lang="scss" scoped>
.items{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.item{
  width: 10.93rem;
  height: 17.5rem;
  background-color: white;
  border-radius: 10px 10px 10px 10px;
  margin: 8px;
  padding-left: 5px;
  img{
    width: 8rem;
    height: 8rem;
    padding: 23px;
  }
  h3{
    font-weight: 500;
    padding-bottom: 10px;
   white-space: nowrap;
   text-overflow:ellipsis;
   overflow: hidden;
  }
  .price{
    color: #fd3f3f;
    font-size: 1.2rem;
    line-height: 2rem;
    font-weight:bold ;

  }
}
</style>
